package com.tiancheng.trade.order.service.impl;

import com.tiancheng.trade.order.bo.AbnormalPayOrderBO;
import com.tiancheng.trade.order.mapper.AbnormalPayOrderMapper;
import com.tiancheng.trade.order.model.AbnormalPayOrder;
import com.tiancheng.trade.order.service.AbnormalPayOrderService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

/**
 * 异常支付订单service接口实现
 *
 * @author kellen
 * @date 2024/4/27
 */
@Service
public class AbnormalPayOrderServiceImpl implements AbnormalPayOrderService {

    @Resource
    private AbnormalPayOrderMapper abnormalPayOrderMapper;

    @Override
    public int save(AbnormalPayOrderBO abnormalPayOrderBO) {
        List<AbnormalPayOrder> abnormalPayOrders = new ArrayList<>();
        Stream.of(abnormalPayOrderBO.getOrderIds()).forEach(orderId -> {
            AbnormalPayOrder abnormalPayOrder = new AbnormalPayOrder();
            abnormalPayOrder.setUid(abnormalPayOrderBO.getUid());
            abnormalPayOrder.setOrderId(orderId);
            abnormalPayOrder.setFlowId(abnormalPayOrderBO.getFlowId());
            abnormalPayOrder.setPaymentId(abnormalPayOrderBO.getPaymentId());
            abnormalPayOrder.setPayTime(abnormalPayOrderBO.getPayTime());
            abnormalPayOrder.setCreatedDt(LocalDateTime.now());
            abnormalPayOrders.add(abnormalPayOrder);
        });
        return abnormalPayOrderMapper.saveBatch(abnormalPayOrders);
    }
}
